package Presentacion;

import Clases.AdelantoAguinaldo;
import Clases.Empleado;
import Control.ControlAdelantoAguinaldo;
import Control.ControlEmpleado;
import de.javasoft.plaf.synthetica.SyntheticaLookAndFeel;
import java.text.DecimalFormat;
import java.text.NumberFormat;
import java.text.ParseException;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.ImageIcon;
import javax.swing.JOptionPane;
import javax.swing.RowFilter;
import javax.swing.SwingUtilities;
import javax.swing.UIManager;
import javax.swing.event.DocumentEvent;
import javax.swing.event.DocumentListener;
import javax.swing.table.DefaultTableModel;
import javax.swing.table.TableRowSorter;
import javax.swing.text.NumberFormatter;

public class ManejoAdelantoAguinaldo extends javax.swing.JFrame {

    private static ManejoAdelantoAguinaldo instancia = null;
    ControlAdelantoAguinaldo controlAdelanto = ControlAdelantoAguinaldo.obtenerInstancia();
    ControlEmpleado controlE = ControlEmpleado.obtenerInstancia();
    NumberFormat numberFormat = (DecimalFormat) DecimalFormat.getNumberInstance();
    private TableRowSorter sorter = new TableRowSorter();
    private ImageIcon iconoError;

    public ManejoAdelantoAguinaldo() {
        initComponents();
        inicioTooltops();
    }

    public static ManejoAdelantoAguinaldo obtenerInstancia() {
        if (instancia == null) {
            instancia = new ManejoAdelantoAguinaldo();
        }
        return instancia;
    }

    public void init() {
        setTitle(" Manejo de Préstamos");
        setLocationRelativeTo(null);
        UIManager.removeAuxiliaryLookAndFeel(UIManager.getLookAndFeel());
        SwingUtilities.updateComponentTreeUI(this);
        try {
            UIManager.removeAuxiliaryLookAndFeel(UIManager.getLookAndFeel());
            SyntheticaLookAndFeel.setWindowsDecorated(false);
            UIManager.setLookAndFeel("de.javasoft.plaf.synthetica.SyntheticaAluOxideLookAndFeel");
            SwingUtilities.updateComponentTreeUI(this);

        } catch (Exception ex) {
            try {
                UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
        this.limpiar();
        sorter.setModel(jTable1.getModel());
        jTable1.setRowSorter(sorter);
        jTextField1.getDocument().addDocumentListener(
                new DocumentListener() {
                    public void changedUpdate(DocumentEvent e) {
                        newFilter();
                    }

                    public void insertUpdate(DocumentEvent e) {
                        newFilter();
                    }

                    public void removeUpdate(DocumentEvent e) {
                        newFilter();
                    }
                });
        jTable1.getColumnModel().getColumn(0).setWidth(jTable1.getColumnModel().getColumn(0).getMinWidth() + 10);
        jTable1.getColumnModel().getColumn(0).setMaxWidth(jTable1.getColumnModel().getColumn(0).getMinWidth() + 10);
        this.llenarTablaAdelantos();
        this.NumberFormat();
        this.setVisible(true);
    }

    private void newFilter() {
        RowFilter<DefaultTableModel, Object> cedulaFilter = null;
        RowFilter<DefaultTableModel, Object> nombreFilter = null;
        List<RowFilter<DefaultTableModel, Object>> filters = new ArrayList<RowFilter<DefaultTableModel, Object>>();
        RowFilter<DefaultTableModel, Object> compoundRowFilter = null;
        try {
            cedulaFilter = RowFilter.regexFilter("(?i)^" + jTextField1.getText(), 1);
            nombreFilter = RowFilter.regexFilter("(?i)^" + jTextField1.getText(), 2);
            filters.add(cedulaFilter);
            filters.add(nombreFilter);
            compoundRowFilter = RowFilter.orFilter(filters);
        } catch (java.util.regex.PatternSyntaxException e) {
            return;
        }
        sorter.setRowFilter(compoundRowFilter);
    }

    public void NumberFormat() {
        numberFormat.setMaximumIntegerDigits(7);
        numberFormat.setMinimumFractionDigits(0);
        numberFormat.setMaximumFractionDigits(0);
        numberFormat.setMinimumIntegerDigits(2);
        NumberFormatter nfr = new NumberFormatter(numberFormat);
        this.jTextField4.setFormatterFactory(new javax.swing.text.DefaultFormatterFactory(nfr));

        this.jTextField5.setFormatterFactory(new javax.swing.text.DefaultFormatterFactory(nfr));
    }

    public void setCampos(Long cedula, String nombre, Double aguinaldo) {
        this.labelCedula.setText(cedula.toString());
        this.labelNombre.setText(nombre);
        String aguinaldoD = "";
        try {
            aguinaldoD = String.valueOf(numberFormat.parse(aguinaldo.toString()).doubleValue());
        } catch (Exception e) {
            aguinaldoD = "0";
        }
         this.NumberFormat();
        this.jTextField5.setValue(aguinaldo);
        /*try{
            this.jTextField5.commitEdit();
        }catch(ParseException e){
            
        }
       */
        ControlEmpleado controlE = ControlEmpleado.obtenerInstancia();
        this.labelCodigo.setText(String.valueOf(controlE.getEmpleadoCedula((cedula)).getCodigo()));
    }

    public void limpiarCrear() {
        this.labelCedula.setText("____________________");
        this.labelNombre.setText("____________________");
        this.labelCodigo.setText("____________________");
        this.jTextField5.setText("");
        this.jTextField4.setText("");
        jTextField4.setValue(null);
        jTextField5.setValue(null);
    }

    public void limpiarBuscar() {
        this.jTextField1.setText("");
    }

    public void limpiar() {
        limpiarCrear();
        limpiarBuscar();
        ocultarLabels();
    }

    public void llenarTablaAdelantos() {
        ArrayList<AdelantoAguinaldo> adelantos = ControlAdelantoAguinaldo.obtenerInstancia().getAdelantos();
        DefaultTableModel m = (DefaultTableModel) jTable1.getModel();
        ControlEmpleado controlEmpleado = ControlEmpleado.obtenerInstancia();
        try {
            while (m.getRowCount() > 0) {
                m.removeRow(0);
            }
            for (int i = 0; i < adelantos.size(); i++) {
                Empleado e = controlEmpleado.getEmpleadoNum(adelantos.get(i).getEmpleado().getNumEmpleado());
                m.insertRow(m.getRowCount(), new Object[]{new Boolean(false),
                    e.getCodigo(), e.getNombre() + " " + e.getApellido1(),
                    adelantos.get(i).getFecha(), adelantos.get(i).getAdelanto()});
            }
        } catch (Exception e) {
            System.out.println(e.getCause());
            System.out.println(e.getMessage());
        }
    }

    public double calcularAguinaldoDisponible(Long cedulaEmpleado) {
        Empleado empleado = controlE.getEmpleadoCedula(cedulaEmpleado);
        ManejoAguinaldo aguinaldo = ManejoAguinaldo.obtenerInstancia();
        return aguinaldo.calcularAguinaldo(empleado);
    }

    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jTabbedPane1 = new javax.swing.JTabbedPane();
        jPanel2 = new javax.swing.JPanel();
        jScrollPane1 = new javax.swing.JScrollPane();
        jTable1 = new javax.swing.JTable();
        jLabel2 = new javax.swing.JLabel();
        jTextField1 = new javax.swing.JTextField();
        jButton1 = new javax.swing.JButton();
        jPanel1 = new javax.swing.JPanel();
        jLabel3 = new javax.swing.JLabel();
        jLabel4 = new javax.swing.JLabel();
        jButton2 = new javax.swing.JButton();
        jLabel5 = new javax.swing.JLabel();
        jButton3 = new javax.swing.JButton();
        jLabel6 = new javax.swing.JLabel();
        jTextField4 = new javax.swing.JFormattedTextField();
        jLabelEmpleado = new javax.swing.JLabel();
        jLabelAdelanto = new javax.swing.JLabel();
        labelCedula = new javax.swing.JLabel();
        labelNombre = new javax.swing.JLabel();
        jLabel7 = new javax.swing.JLabel();
        labelCodigo = new javax.swing.JLabel();
        jTextField5 = new javax.swing.JFormattedTextField();
        jLabel1 = new javax.swing.JLabel();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setMinimumSize(new java.awt.Dimension(580, 350));

        jTable1.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {

            },
            new String [] {
                "", "Código", "Nombre", "Fecha", "Adelanto"
            }
        ) {
            Class[] types = new Class [] {
                java.lang.Boolean.class, java.lang.Long.class, java.lang.String.class, java.lang.String.class, java.lang.Double.class
            };
            boolean[] canEdit = new boolean [] {
                true, false, false, false, false
            };

            public Class getColumnClass(int columnIndex) {
                return types [columnIndex];
            }

            public boolean isCellEditable(int rowIndex, int columnIndex) {
                return canEdit [columnIndex];
            }
        });
        jScrollPane1.setViewportView(jTable1);

        jLabel2.setFont(new java.awt.Font("Tahoma", 1, 12)); // NOI18N
        jLabel2.setText("Buscar:");

        jTextField1.setToolTipText("Ingrese la cedula o el nombre del empleado.");

        jButton1.setText("Eliminar");

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 543, Short.MAX_VALUE)
                    .addGroup(javax.swing.GroupLayout.Alignment.LEADING, jPanel2Layout.createSequentialGroup()
                        .addComponent(jLabel2)
                        .addGap(18, 18, 18)
                        .addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, 204, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(0, 0, Short.MAX_VALUE))
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addGap(0, 0, Short.MAX_VALUE)
                        .addComponent(jButton1)))
                .addContainerGap())
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel2Layout.createSequentialGroup()
                .addGap(13, 13, 13)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel2)
                    .addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 173, Short.MAX_VALUE)
                .addGap(18, 18, 18)
                .addComponent(jButton1))
        );

        jTabbedPane1.addTab("Consultar Adelanto", jPanel2);

        jLabel3.setFont(new java.awt.Font("Tahoma", 1, 12)); // NOI18N
        jLabel3.setText("Cédula:");

        jLabel4.setFont(new java.awt.Font("Tahoma", 1, 12)); // NOI18N
        jLabel4.setText("Nombre:");

        jButton2.setText("Buscar Empleado");
        jButton2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton2ActionPerformed(evt);
            }
        });

        jLabel5.setFont(new java.awt.Font("Tahoma", 1, 12)); // NOI18N
        jLabel5.setText("Adelanto:");

        jButton3.setText("Crear");
        jButton3.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton3ActionPerformed(evt);
            }
        });

        jLabel6.setFont(new java.awt.Font("Tahoma", 1, 12)); // NOI18N
        jLabel6.setText("Aguinaldo:");

        jTextField4.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jTextField4ActionPerformed(evt);
            }
        });
        jTextField4.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                jTextField4KeyPressed(evt);
            }
        });

        jLabelEmpleado.setText("x");
        jLabelEmpleado.setMaximumSize(new java.awt.Dimension(24, 24));
        jLabelEmpleado.setMinimumSize(new java.awt.Dimension(22, 22));
        jLabelEmpleado.setPreferredSize(new java.awt.Dimension(22, 22));

        jLabelAdelanto.setText("x");
        jLabelAdelanto.setMaximumSize(new java.awt.Dimension(24, 24));
        jLabelAdelanto.setMinimumSize(new java.awt.Dimension(22, 22));
        jLabelAdelanto.setPreferredSize(new java.awt.Dimension(22, 22));

        labelCedula.setText("_________________");

        labelNombre.setText("_________________");

        jLabel7.setFont(new java.awt.Font("Tahoma", 1, 12)); // NOI18N
        jLabel7.setText("Código:");

        labelCodigo.setText("_________________");

        jTextField5.setEditable(false);
        jTextField5.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jTextField5ActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGap(60, 60, 60)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                        .addComponent(jLabel6)
                        .addComponent(jLabel5, javax.swing.GroupLayout.Alignment.LEADING)
                        .addComponent(jLabel4, javax.swing.GroupLayout.Alignment.LEADING))
                    .addComponent(jLabel3)
                    .addComponent(jLabel7))
                .addGap(18, 18, 18)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addComponent(labelCedula, javax.swing.GroupLayout.PREFERRED_SIZE, 153, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(31, 31, 31)
                        .addComponent(jButton2)
                        .addGap(18, 18, 18)
                        .addComponent(jLabelEmpleado, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(jButton3)
                            .addGroup(jPanel1Layout.createSequentialGroup()
                                .addComponent(jTextField4, javax.swing.GroupLayout.PREFERRED_SIZE, 188, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGap(16, 16, 16)))
                        .addGap(18, 18, 18)
                        .addComponent(jLabelAdelanto, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                        .addComponent(jTextField5, javax.swing.GroupLayout.Alignment.LEADING)
                        .addComponent(labelCodigo, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addComponent(labelNombre, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 133, Short.MAX_VALUE)))
                .addContainerGap(82, Short.MAX_VALUE))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGap(29, 29, 29)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jButton2)
                            .addComponent(jLabelEmpleado, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(labelCedula)))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(jLabel3)))
                .addGap(18, 18, 18)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel7)
                    .addComponent(labelCodigo))
                .addGap(18, 18, 18)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(labelNombre, javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jLabel4, javax.swing.GroupLayout.Alignment.TRAILING))
                .addGap(18, 18, 18)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel6)
                    .addComponent(jTextField5, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jTextField4, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel5)
                    .addComponent(jLabelAdelanto, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addComponent(jButton3)
                .addGap(28, 28, 28))
        );

        jTabbedPane1.addTab("Crear Adelanto", jPanel1);

        jLabel1.setFont(new java.awt.Font("Tahoma", 1, 18)); // NOI18N
        jLabel1.setText("Gestión de adelantos de aguinaldo");

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jTabbedPane1)
                .addContainerGap())
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(jLabel1)
                .addGap(131, 131, 131))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel1)
                .addGap(18, 18, 18)
                .addComponent(jTabbedPane1)
                .addGap(8, 8, 8))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed
        Empleados empleado = new Empleados();
        empleado.init("adelantoAguinaldo");
    }//GEN-LAST:event_jButton2ActionPerformed

    private void inicioTooltops() {
        iconoError = new ImageIcon(getClass().getResource("/Imagenes/warning.png"));

        jLabelAdelanto.setIcon(iconoError);
        jLabelAdelanto.setToolTipText("El adelanto debe ser mayor a 0 y menor al aguinaldo.");

        jLabelEmpleado.setIcon(iconoError);
        jLabelEmpleado.setToolTipText("Debe buscar el empleado primero");

        ocultarLabels();
    }

    private void ocultarLabels() {
        jLabelAdelanto.setVisible(false);
        jLabelEmpleado.setVisible(false);
    }

    private boolean validarAdelantoAguinaldo() {
        ocultarLabels();
        boolean itsOk = true;

        String cedula = labelCedula.getText().trim();
        if (Character.isDigit(cedula.charAt(0)) == false) {
            jLabelEmpleado.setVisible(true);
            itsOk = false;
        }
        try {
            double adelanto = jTextField4.getText().trim().isEmpty() ? 0 : numberFormat.parse(jTextField4.getText()).doubleValue();
            double aguinaldo = jTextField5.getText().trim().isEmpty() ? 0 : numberFormat.parse(jTextField5.getText()).doubleValue();
            if (adelanto < 1000 || adelanto > aguinaldo) {
                jLabelAdelanto.setVisible(true);
                itsOk = false;
            }
        } catch (Exception e) {
            jLabelAdelanto.setVisible(true);
            itsOk = false;
        }
        return itsOk;
    }

    void crear() {
        if (validarAdelantoAguinaldo()) {
            try {
                Long cedula = labelCedula.getText().trim().isEmpty() ? null : Long.valueOf(labelCedula.getText());
                String nombre = labelNombre.getText();
                String aguinaldo = jTextField5.getText();
                double adelanto = jTextField4.getText().trim().isEmpty() ? 0 : numberFormat.parse(jTextField4.getText()).doubleValue();
                Date fecha = new Date();
                if (adelanto != 0) {
                    Empleado empleado = controlE.getEmpleadoCedula(cedula);
                    AdelantoAguinaldo adelantoA = new AdelantoAguinaldo(empleado, fecha, adelanto);
                    long inserto = controlAdelanto.insertarAdelanto(adelantoA);
                    this.llenarTablaAdelantos();
                    if (inserto != 0) {
                        JOptionPane.showMessageDialog(null, "Adelanto de asguinaldo creado exitosamente", "Mensaje", JOptionPane.INFORMATION_MESSAGE);
                    } else {
                        JOptionPane.showMessageDialog(null, "Problemas al crear el adelanto de aguinaldo", "Mensaje", JOptionPane.ERROR_MESSAGE);
                    }
                    limpiar();
                    dispose();
                }
            } catch (ParseException ex) {
                Logger.getLogger(ManejoAdelantoAguinaldo.class.getName()).log(Level.SEVERE, null, ex);
            }

        }
    }

    private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton3ActionPerformed
        this.crear();
    }//GEN-LAST:event_jButton3ActionPerformed

    private void jTextField4KeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_jTextField4KeyPressed
        int key = evt.getKeyCode();
        if (key == evt.VK_ENTER) {
            this.crear();
        }
    }//GEN-LAST:event_jTextField4KeyPressed

    private void jTextField4ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jTextField4ActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_jTextField4ActionPerformed

    private void jTextField5ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jTextField5ActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_jTextField5ActionPerformed

    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(ManejoAdelantoAguinaldo.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(ManejoAdelantoAguinaldo.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(ManejoAdelantoAguinaldo.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(ManejoAdelantoAguinaldo.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new ManejoAdelantoAguinaldo().setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton jButton1;
    private javax.swing.JButton jButton2;
    private javax.swing.JButton jButton3;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabelAdelanto;
    private javax.swing.JLabel jLabelEmpleado;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JTabbedPane jTabbedPane1;
    private javax.swing.JTable jTable1;
    private javax.swing.JTextField jTextField1;
    private javax.swing.JFormattedTextField jTextField4;
    private javax.swing.JFormattedTextField jTextField5;
    private javax.swing.JLabel labelCedula;
    private javax.swing.JLabel labelCodigo;
    private javax.swing.JLabel labelNombre;
    // End of variables declaration//GEN-END:variables
}
